{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Decompress Run-Length Encoded List"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: decompressRLElist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #解压缩编码列表"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个以行程长度编码压缩的整数列表 <code>nums</code> 。</p>\n",
    "\n",
    "<p>考虑每对相邻的两个元素 <code>[freq, val] = [nums[2*i], nums[2*i+1]]</code> （其中 <code>i >= 0</code> ），每一对都表示解压后子列表中有 <code>freq</code> 个值为 <code>val</code> 的元素，你需要从左到右连接所有子列表以生成解压后的列表。</p>\n",
    "\n",
    "<p>请你返回解压后的列表。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,2,3,4]\n",
    "<strong>输出：</strong>[2,4,4,4]\n",
    "<strong>解释：</strong>第一对 [1,2] 代表着 2 的出现频次为 1，所以生成数组 [2]。\n",
    "第二对 [3,4] 代表着 4 的出现频次为 3，所以生成数组 [4,4,4]。\n",
    "最后将它们串联到一起 [2] + [4,4,4] = [2,4,4,4]。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,1,2,3]\n",
    "<strong>输出：</strong>[1,3,3]\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 <= nums.length <= 100</code></li>\n",
    "\t<li><code>nums.length % 2 == 0</code></li>\n",
    "\t<li><code>1 <= nums[i] <= 100</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [decompress-run-length-encoded-list](https://leetcode.cn/problems/decompress-run-length-encoded-list/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [decompress-run-length-encoded-list](https://leetcode.cn/problems/decompress-run-length-encoded-list/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,2,3,4]', '[1,1,2,3]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        out = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            for j in range(nums[i]):\n",
    "                out.append(nums[i+1])\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        return [i for i,j in zip(nums[1::2],nums[::2]) for _ in range(j)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        return [nums[i] for i in range(1,len(nums),2) for j in range(nums[i-1])]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        a=[]\n",
    "        for i in range(len(nums)):\n",
    "            if i%2==0:\n",
    "                for j in range(nums[i]):\n",
    "                    a.append(nums[i+1])\n",
    "        return a\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        i=0\n",
    "        l=[]\n",
    "        while i<len(nums)-1:\n",
    "            l=l+[nums[i+1]]*nums[i]\n",
    "            i=i+2\n",
    "        return l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            for j in range(nums[i]):\n",
    "                ans.append(nums[i+1])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(0, len(nums) - 1, 2):\n",
    "            ans.extend([nums[i+1]] * nums[i])\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        i = 0\n",
    "        while i <= len(nums) - 1:\n",
    "            for j in range(nums[i]):\n",
    "                res.append(nums[i+1])\n",
    "            i += 2\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        list=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            list.extend([nums[i+1]]*nums[i])\n",
    "        return list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        l = len(nums)\n",
    "        ans=[]\n",
    "        for i in range(0,l,2):\n",
    "            if i+1<l:\n",
    "                ans+=[nums[i+1]]*nums[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        l1=[x for i,x in enumerate(nums) if i%2==0]\n",
    "        l2=[x for i,x in enumerate(nums) if i%2!=0]\n",
    "        t=[]\n",
    "        for i in range(len(l1)):\n",
    "            ans=[]\n",
    "            ans=l2[i]\n",
    "            for j in range(l1[i]):\n",
    "                t.append(ans)\n",
    "        return t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            for j in range(nums[i]):\n",
    "                ans.append(nums[i+1])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ret = list()\n",
    "        n = len(nums)\n",
    "        for i in range(0,n,2):\n",
    "            ret += [nums[i+1]] * nums[i]\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(0, len(nums), 2):\n",
    "            freq , val = nums[i], nums[i + 1]\n",
    "            ans.extend([val] * freq)\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            for j in range(nums[i]):\n",
    "                res.append(nums[i+1])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        list1 = []\n",
    "        list2 = []\n",
    "        result = []\n",
    "        if nums == []:\n",
    "            return result\n",
    "        for i in range(n):\n",
    "            if i % 2 == 0:\n",
    "                list1.append(nums[i])\n",
    "            else:\n",
    "                list2.append(nums[i])\n",
    "        for i in range(len(list1)):\n",
    "            result += [(list2[i])]*list1[i]\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        a=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            for j in range(nums[i]):\n",
    "                a.append(nums[i+1])\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            list1 = [nums[i],nums[i+1]]\n",
    "            list2 = []\n",
    "            for j in range(list1[0]):\n",
    "                list2.append(list1[1])\n",
    "            ans += list2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            tmp = [nums[i+1]]*nums[i]\n",
    "            res += tmp\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            for j in range(nums[i]):\n",
    "                ans.append(nums[i+1])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        res = []\n",
    "        for i in range(0,n,2):\n",
    "            res += [nums[i + 1]] * nums[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        #每隔两位遍历一次数组，第i个数字为新数组的元素个数，第i+1个数字为新数组的元素的值\n",
    "        n=len(nums)\n",
    "        res=[]\n",
    "        for i in range(0,n,2):\n",
    "            res.extend([nums[i+1]]*nums[i])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(int(len(nums)/2)):\n",
    "            freq=nums[2*i]\n",
    "            val=nums[2*i+1]\n",
    "            for j in range(freq):\n",
    "                ans.append(val)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        i = 0\n",
    "        length = len(nums)\n",
    "        ret = []\n",
    "        while i < length:\n",
    "            a, b = nums[i], nums[i + 1]\n",
    "            for j in range(a):\n",
    "                ret.append(b)\n",
    "            i += 2\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res=[]\n",
    "        for i in range(len(nums)//2):\n",
    "            res.extend([nums[2*i+1] for j in range(nums[2*i])])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res=[]\n",
    "        i=0\n",
    "        while i<len(nums):\n",
    "            res.extend([nums[i+1]]*nums[i])\n",
    "            i+=2\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(0, len(nums), 2):\n",
    "            ans.extend([nums[i + 1]] * nums[i])\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(0, len(nums), 2):\n",
    "            ans.extend([nums[i + 1]] * nums[i])\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for n in range(0,len(nums),2):\n",
    "            for i in range(nums[n]):\n",
    "                res.append(nums[n+1])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        ans = []\n",
    "        for i in range(0, n, 2):\n",
    "            ans += [nums[i + 1]] * nums[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(len(nums)//2):\n",
    "            freq, val = nums[2*i], nums[2*i+1]\n",
    "            res = res + [val for _ in range(freq)]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(0, len(nums), 2):\n",
    "            ans.extend([nums[i + 1]] * nums[i])\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            res.extend(nums[i+1] for j in range(nums[i]))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        l=len(nums)\n",
    "        ans=[]\n",
    "        for i in range(0,l//2):\n",
    "            ans+=[nums[2*i+1]]*nums[2*i]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            tmp = [nums[i+1]]*nums[i]\n",
    "            res = res +tmp\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        num = []\n",
    "        count = []\n",
    "        for i in range(1,len(nums),2):\n",
    "            num.append(nums[i])\n",
    "            count.append(nums[i-1])\n",
    "        assert(len(num) == len(count))\n",
    "        res = []\n",
    "        for n, c in zip(num,count):\n",
    "            for _ in range(c):\n",
    "                res.append(n)\n",
    "        return res\n",
    "\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        list=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            list.extend([nums[i+1]]*nums[i])\n",
    "        return list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        num = []\n",
    "        count = []\n",
    "        for i in range(1,len(nums),2):\n",
    "            num.append(nums[i])\n",
    "            count.append(nums[i-1])\n",
    "        assert(len(num) == len(count))\n",
    "        res = []\n",
    "        for n, c in zip(num,count):\n",
    "            for _ in range(c):\n",
    "                res.append(n)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        i = 0\n",
    "        while i < len(nums):\n",
    "            for j in range(nums[i]):\n",
    "                ans.append(nums[i + 1])\n",
    "            i += 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\r\n",
    "        ans = list()\r\n",
    "        for i in range(0,len(nums),2):\r\n",
    "            ans += [nums[i+1]]*nums[i]\r\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        list=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            list.extend([nums[i+1]]*nums[i])\n",
    "        return list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        List=[]\n",
    "        for i in range(0,len(nums)//2):\n",
    "            for _ in range(nums[2*i]):\n",
    "                List.append(nums[2*i+1])\n",
    "        return List\n",
    "            \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        idx = 0\n",
    "        n = len(nums)\n",
    "        ans = []\n",
    "        while idx < n:\n",
    "            for i in range(nums[idx]):\n",
    "                ans.append(nums[idx+1])\n",
    "            idx += 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        l, r = 0, 1\n",
    "        while r < len(nums):\n",
    "            ans += [nums[r]] * nums[l]\n",
    "            l += 2\n",
    "            r += 2\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res=[]\n",
    "        for i in range(int(len(nums)/2)):\n",
    "            a=nums[i*2]\n",
    "            b=nums[i*2+1]\n",
    "            for j in range(a):\n",
    "                res.append(b)\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(len(nums)//2):\n",
    "            res.extend([nums[2*i+1]]*nums[2*i])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        freq = nums[::2]\n",
    "        val = nums[1::2]\n",
    "        ans = []\n",
    "        for i in range(len(freq)):\n",
    "            ans.extend([val[i]] * freq[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\r\n",
    "        res = []\r\n",
    "        for i in range(0, len(nums), 2):\r\n",
    "            res += [nums[i + 1]] * nums[i]\r\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(0, len(nums), 2):\n",
    "            res += [nums[i + 1]] * nums[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(0,len(nums)-1,2):\n",
    "            fre=nums[i]\n",
    "            num=nums[i+1]\n",
    "            for _ in range(fre):\n",
    "                ans.append(num)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n=len(nums)\n",
    "        lst=[]\n",
    "        for i in range(0,n,2):\n",
    "            lst.extend([nums[i+1]]*(nums[i]))\n",
    "        return lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n=len(nums)\n",
    "        res=[]\n",
    "        for i in range(0,n,2):\n",
    "            # print(nums[i])\n",
    "            for j in range(nums[i]):\n",
    "\n",
    "                res.append(nums[i+1])\n",
    "        # print(res)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = list();\n",
    "        for i in range(0, len(nums), 2):\n",
    "            ans.extend([nums[i + 1]] * nums[i])\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        #每隔两位遍历一次数组，第i个数字为新数组的元素个数，第i+1个数字为新数组的元素的值\n",
    "        \n",
    "        res=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            res.extend([nums[i+1]]*nums[i])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(0, len(nums), 2):\n",
    "            ans.extend([nums[i + 1]] * nums[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(0, len(nums), 2):\n",
    "            ans.extend([nums[i + 1]] * nums[i])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        #每隔两位遍历一次数组，第i个数字为新数组的元素个数，第i+1个数字为新数组的元素的值\n",
    "        \n",
    "        res=[]\n",
    "        for i in range(0,len(nums),2):\n",
    "            res.extend([nums[i+1]]*nums[i])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        ans = []\n",
    "        for i in range(0,n,2):\n",
    "            for _ in range(nums[i]):\n",
    "                ans.append(nums[i+1])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n=len(nums)\n",
    "        res=[]\n",
    "        for i in range(0,n,2):\n",
    "            res+=nums[i]*[nums[i+1]]\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        out = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            out += [nums[i+1]] * nums[i]\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        #每隔两位遍历一次数组，第i个数字为新数组的元素个数，第i+1个数字为新数组的元素的值\n",
    "        n=len(nums)\n",
    "        res=[]\n",
    "        for i in range(0,n,2):\n",
    "            res.extend([nums[i+1]]*nums[i])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res: List[int] = []\n",
    "        for x, y in zip(nums[::2], nums[1::2]):\n",
    "            res.extend(x * [y])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n=len(nums)\n",
    "        res=[]\n",
    "        for i in range(0,n,2):\n",
    "            for j in range(nums[i]):\n",
    "                res.append(nums[i+1])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "\n",
    "        ans = []\n",
    "        for ii in range(len(nums)//2):\n",
    "            freq = nums[2 *ii + 0]\n",
    "            val = nums[2 * ii + 1]\n",
    "            \n",
    "            ans += [val] * freq\n",
    "        \n",
    "        print(\"ans: \", ans)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        list_jiema=[]\n",
    "        cishu=len(nums)//2\n",
    "        i=1\n",
    "        while cishu:\n",
    "            cishu-=1\n",
    "            for j in range(nums[i-1]):\n",
    "                list_jiema.append(nums[i])\n",
    "            i+=2\n",
    "        return list_jiema"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            ans += nums[i] * [nums[(i+1)]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(0,len(nums),2):\n",
    "            ans.extend([nums[i+1]] * nums[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(0, len(nums), 2):\n",
    "            ans += [nums[i + 1]] * nums[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        n = len(nums)\n",
    "        ans = []\n",
    "        for i in range(0,n,2):\n",
    "            ans.extend([nums[i+1]] * nums[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans =list()\n",
    "        for i in range(0,len(nums),2):\n",
    "            ans.extend(nums[i]*[nums[i+1]])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(0, len(nums) - 1, 2):\n",
    "            next = i + 1\n",
    "            multi = nums[i]\n",
    "            temp = []\n",
    "            while multi != 0:\n",
    "                temp.append(nums[next])\n",
    "                multi -= 1\n",
    "            ans += temp\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        # res = []\n",
    "        # for index in range(0, len(nums), 2):\n",
    "        #     for _ in range(nums[index]):\n",
    "        #         res.append(nums[index+1])\n",
    "        # return res\n",
    "        ans = list()\n",
    "        for i in range(0, len(nums), 2):\n",
    "            ans.extend([nums[i + 1]] * nums[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(0, len(nums), 2):\n",
    "            for n in range(nums[i]):\n",
    "                res.append(nums[i + 1])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(0, len(nums), 2):\n",
    "            new = [nums[i + 1]] * nums[i]\n",
    "            res += new\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def decompressRLElist(self, nums: List[int]) -> List[int]:\n",
    "        result = []\n",
    "        length = len(nums)\n",
    "        for i in range(0, length-1, 2):\n",
    "            print(i)\n",
    "            freq = nums[i]\n",
    "            num = nums[i+1]\n",
    "            result.extend([num] * freq)\n",
    "        return result\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
